import traceback
import logging

logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(name)-12s  %(levelname)-8s %(message)s',
                    filename="my.log",
                    datefmt="%m-%d %H:%M:%S",        
                    filemode='a')

mylogging = logging.getLogger('Demo')


try:
    mylogging.debug("This is my log")
    j='fdk'
    k=int(j)
    
except:
    exption_str=traceback.format_exc()
    mylogging.error( "Unexpected error:\n %s ",exption_str )

